package com.hiv.controller.wechat;

import com.hiv.common.BaseController;
import com.hiv.common.PageInfo;
import com.hiv.common.WebResponse;
import com.hiv.common.param.page.PageQuerySamplingRecordParam;
import com.hiv.mapper.domain.Admin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.hiv.mapper.domain.SamplingRecord;
import com.hiv.service.SamplingRecordService;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zhanghong
 * @version XcxSamplingRecordController.java, v 0.1 2022-09-20 XcxSamplingRecordController Exp $$
 */
@RestController
@RequestMapping("/wechat/samplingRecord")
@Api(value = "采样数据模块", tags = {"【小程序端】采样数据模块"})
public class XcxSamplingRecordController extends BaseController {
    @Autowired
    private SamplingRecordService samplingRecordService;

    @ApiOperation(value = "分页查询(通用)", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<SamplingRecord>> pageQuery(HttpServletRequest request, @RequestBody PageQuerySamplingRecordParam param) {
        return WebResponse.build(samplingRecordService.pageQuery(null, param));
    }

    @ApiOperation(value = "分页查询(for doctor)", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/doctorPageQuery")
    public WebResponse<PageInfo<SamplingRecord>> forDoctorPageQuery(HttpServletRequest request, @RequestBody PageQuerySamplingRecordParam param) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(samplingRecordService.forDoctorPageQuery(param));
    }

    @ApiOperation(value = "根据盒子编码查询盒子里包含的采样数据", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/listSamplingByBoxCode/{boxCode}")
    public WebResponse<List<SamplingRecord>> listSamplingByBoxCode(HttpServletRequest request, @PathVariable("boxCode") String boxCode) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(samplingRecordService.listSamplingByBoxCode(boxCode));
    }

    @ApiOperation(value = "根据快递编号查询快递里包含的采样数据", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/listSamplingByExpressCode/{expressCode}")
    public WebResponse<List<SamplingRecord>> listSamplingByExpressCode(HttpServletRequest request, @PathVariable("expressCode") String expressCode) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(samplingRecordService.listSamplingByExpressCode(expressCode));
    }

    @ApiOperation(value = "根据id查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{id}")
    public WebResponse<SamplingRecord> getById(HttpServletRequest request, @PathVariable("id") long id) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(samplingRecordService.getById(id));
    }

    @ApiOperation(value = "保存采样数据", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/save")
    public WebResponse<Boolean> save(HttpServletRequest request, @RequestBody SamplingRecord param) {
        Admin admin = validUserLoginAndGet(request, Admin.class);
        param.setSamplerId(admin.getId());
        return WebResponse.build(samplingRecordService.save(param));
    }

    @ApiOperation(value = "删除", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/delete")
    public WebResponse<Boolean> delete(HttpServletRequest request, @RequestParam String ids) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(samplingRecordService.deleteByIds(ids));
    }

    @ApiOperation(value = "分页查询(快递单号/批次号)", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/union/pageQuery")
    public WebResponse<PageInfo<SamplingRecord>> unionPageQuery(HttpServletRequest request, @RequestBody PageQuerySamplingRecordParam param) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(samplingRecordService.unionPageQuery(param));
    }

    @ApiOperation(value = "重新采集", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/resampling")
    public WebResponse<Boolean> resampling(HttpServletRequest request, @RequestBody List<Long> ids) {
        Admin admin = validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(samplingRecordService.resampling(ids));
    }
}
